package org.bookie.core.services;


import org.bookie.model.Role;
import org.bookie.model.User;

/**
 * Authentication context persisted within session service model.
 * Allow the user to be retrieved at any time throughout the application.
 * 
 * @author zubairov
 *
 */
public interface IAuthenticationContext {

	public static enum AuthenticationResult{
		SUCCESS, USER_NOT_FOUND, USER_NOT_ACTIVE, EMAIL_PASSWORD_DISCREPANCE
	}
	/**
	 * Returns currently autheticated user or null if none is there
	 * @return
	 */
	public abstract User getUser();
	
	/**
	 * Authenticate user by given email and password
	 * @param email E-Mail
	 * @param password Password
	 * @param rememberMe - flag to remember user authentication details
	 * @return AuthenticationResult
	 */
	public abstract AuthenticationResult authenticate(String email, String password, boolean rememberMe);

	/**
	 * Authenticate user by given email
	 * 
	 * This method is used when user is already authenticated by the third party (e.g. Facebook, OpenID)
	 * 
	 * @param email E-Mail
	 * @param password Password
	 * @param rememberMe - flag to remember user authentication details
	 * @return AuthenticationResult
	 */
	public abstract AuthenticationResult authenticate(String email);
	
	/**
	 * Returns true when user has given role.
	 * @param role
	 * @return <code>true</code> if User has the proper role. <code>false</code> otherwise.
	 */
	public abstract boolean isUserInRole(Role role);
	
	/**
	 * Get if the user is already authenticated.
	 * @return <code>true</code> if user is already authenticated, <code>false</code> otherwise.
	 */
    public abstract boolean isUserAuthenticated();

	/**
	 * Executes logout, cleanup the cookies 
	 */
    public abstract void logout();
	
}
